package realQuestion.B;

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] people = new int[n][2];

        for (int i = 0; i < n; i++) {
            people[i][0] = scanner.nextInt(); // Arrival time
            people[i][1] = scanner.nextInt(); // Return time to ground floor
        }

        Arrays.sort(people, (a, b) -> a[0] - b[0]);

        // Priority queue to simulate the two elevators
        PriorityQueue<Integer> elevator1 = new PriorityQueue<>();
        PriorityQueue<Integer> elevator2 = new PriorityQueue<>();

        int currentTime = 0;
        int totalTime = 0;

        for (int i = 0; i < n; i++) {
            if (elevator1.isEmpty() || elevator1.peek() <= currentTime) {
                elevator1.offer(currentTime + people[i][1]);
                currentTime += people[i][0];
            } else if (elevator2.isEmpty() || elevator2.peek() <= currentTime) {
                elevator2.offer(currentTime + people[i][1]);
                currentTime += people[i][0];
            } else {
                int time1 = elevator1.peek();
                int time2 = elevator2.peek();
                if (time1 <= time2) {
                    elevator1.poll();
                    elevator1.offer(time1 + people[i][1]);
                    currentTime = time1;
                } else {
                    elevator2.poll();
                    elevator2.offer(time2 + people[i][1]);
                    currentTime = time2;
                }
            }
            totalTime = currentTime;
        }

        System.out.println(totalTime);
    }
}